package com.pi2e.view.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.pi2e.R;
import com.pi2e.common.KdxfSpeechHelper;
import com.pi2e.common.KdxfSpeechHelper.SpeechCompletedListener;
import com.pi2e.view.base.BaseActivity;
import com.pi2e.view.common.FootView;
import com.pi2e.view.common.HeaderView;

public class EndGuideActivity extends BaseActivity implements OnClickListener {

	 
	String content ="祝您入住愉快，拜拜！" ;
	LinearLayout liy_content ;
	int srcid = R.drawable.test_end_01 ;
	Handler handler = new Handler() ;
	
	Runnable runEnd = new Runnable() {
		
		@Override
		public void run() {
			content = "返回休息了" ;
			srcid = R.drawable.test_end_02 ;
			liy_content.setBackground(getResources().getDrawable(R.drawable.test_end_02));
			KdxfSpeechHelper.startPlay(content, new SpeechCompletedListener() {
				
				@Override
				public boolean onPreperPlay() {
					// TODO Auto-generated method stub
					return false;
				}
				
				@Override
				public boolean onPlay(String Msg) {
					// TODO Auto-generated method stub
					return false;
				}
				
				@Override
				public boolean onError() {
					// TODO Auto-generated method stub
					return false;
				}
				
				@Override
				public boolean onCompleted() {
					
					return false;
				}
			});
		}
	};
	Runnable runStart = new Runnable() {
		
		@Override
		public void run() {
			KdxfSpeechHelper.startPlay(content, new SpeechCompletedListener() {
				
				@Override
				public boolean onPreperPlay() {
					// TODO Auto-generated method stub
					return false;
				}
				
				@Override
				public boolean onPlay(String Msg) {
					// TODO Auto-generated method stub
					return false;
				}
				
				@Override
				public boolean onError() {
					// TODO Auto-generated method stub
					return false;
				}
				
				@Override
				public boolean onCompleted() {
					handler.postDelayed(runEnd, KdxfSpeechHelper.AFTER_SPEECH_DELAY_TIME);
					return false;
				}
			});
			
			
		}
	};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		handler.postDelayed(runStart, KdxfSpeechHelper.BEFORE_SPEECH_DELAY_TIME) ;
	}
	@Override
	public HeaderView initHeaderView() {
		return null;
	}

	@Override
	public void setContentView() {
		setContentView(R.layout.activity_end);

	}

	@Override
	public void initView() {
		liy_content = (LinearLayout) findViewById(R.id.liy_content) ;

	}

	@Override
	public void initFootView() {
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		if (null !=handler && null !=runStart) {
			KdxfSpeechHelper.onDestroy();
			handler.removeCallbacks(runStart);
		}
	}
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN&&srcid == R.drawable.test_end_02) {
			Intent it = new Intent(EndGuideActivity.this,MainActivity.class) ;
			startActivity(it);
			finish();
		}
		return super.onTouchEvent(event);
	}

}
